<?php
/**
 * 
 */
class ApidevModule extends CWebModule
{
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'api.models.*',
			'api.components.*',
		));
		
		// In the init method of ApiModule, specify the copied 'api-layout' layout to be used.
		$this->layout = 'main';
		// set the default controller ID is get
		$this->defaultController = 'default';
		
		// reset the errorHandler. PS: only this way works.
		$components = array(
			'errorHandler' => array(
					'errorAction' => '/api/default/error',
			),
		);
		
		Yii::app()->setComponents($components);
		// add these components to this instance
		$this->setComponents($components);
		
		// set the differnet DB
		Yii::app()->db->setActive(false);
		Yii::app()->db->connectionString = 'mysql:host=localhost;dbname=yamiifi_dev';
		
		
		$lang = Yii::app()->request->getParam('lang', 'en_gb');
		BUtils::SetLanguage($lang);
		Yii::app()->setTimeZone('Europe/Helsinki');
	}

	public function beforeControllerAction($controller, $action)
	{
		if (parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			//TODO: need to set timezone by user settings. 2012.05.23
			return true;
		}
		else
			return false;
	}
}
